package q2190_mostFrequent;

public class Solution {
    /*
    hash的经典题型 统计key后面的数字出现频率并放入到一个int数组中
    然后找最大值即可
     */
    public int mostFrequent(int[] nums, int key) {
        int[] freq = new int[1001];
        for (int i = 1; i < nums.length; i++) {
            if (nums[i - 1] == key) ++freq[nums[i]];
        }
        int ans = 0, f = freq[0];
        for (int i = 0; i < 1001; i++) {
            if (freq[i] > f) {
                ans = i;
                f = freq[i];
            }
        }
        return ans;
    }
}
